# 当多个类中有相同之处时，可以将相同的提取出来写到一个类中，这个类我们称之为父类。即可以通过引用父类使得一段代码缩写成一句，当需要重复写这段代码时可以减轻工作量。
class Pet():
    def __init__(self,name,health,love):
        self.name=name
        self.health=health
        self.love=love
    def show(self):
        print("宠物名字："+self.name)
        print("健康值："+str(self.health))
        print("好感度："+str(self.love))

# 电子宠物狗
class Dog(Pet):
    #子类的构造当中调用父类的构造
    def __init__(self,name,health,love,strain):
        super().__init__(name,health,love)
        self.strain=strain
    def show(self):
        super().show()
        print("品种："+self.strain)
    def catchpan(self):
        print("接飞盘")

class Penguin(Pet):
    def __init__(self,name,health,love,sex):
        super().__init__(name,health,love)
        self.sex=sex
    def show(self):
        super().show()
        print("性别："+self.sex)
    def swimm(self):
        print("游泳")

class Master():
    def get_pet(self,type):
        if type=="Dog":
            awang=Dog("阿旺",100,100,"金毛")
            return awang
        else:
            qmei=Penguin("阿Q",100,100,"女")
            return qmei
    def feed_pet(self,pet):
        pet.health +=1
    def play(self,pet):
        if isinstance(pet,Dog):
            pet.catchpan()
        if isinstance(pet,Penguin):
            pet.swimm()

# awang=Dog("阿旺",100,100,"金毛")
# awang.show()
master=Master()
pet = master.get_pet("Dog")
master.feed_pet(pet)
pet.show()
master.play(pet)
